import math
from random import random

first_name = "李、王、张、刘、陈、杨、赵、黄、周、吴、徐、孙、胡、朱、高、林、何、郭、马、罗、梁、宋、郑、谢、韩、唐、欧阳、东方、董、" \
             "萧、程、曹、袁、邓、许、傅、沈、曾、彭、吕、苏、卢、蒋、蔡、贾、丁、魏、薛、叶、阎、余、潘、杜、戴、夏、钟、汪、田、" \
             "任、姜、范、方、石、姚、谭、廖、邹、熊、金、陆、郝、孔、白 "
last_name = "睿、浩、博、瑞、昊、悦、妍、涵、玥、蕊、子、梓、浩、宇、俊、轩、宇、泽、杰、豪、雨、梓、欣、子、思、蔼、仁、容、德、" \
            "轩、贤、良、伦、正、清、义、诚、直、道、颖、灵、睿、锐、哲、慧、敦、迪、明、晓、显、悉、晰、维、学、思、悟、" \
            "析、文、书、勤、俊、威、英、健、壮、焕、挺、秀、伟、武、雄、巍、松、柏、山、石、" \
            "婵、娟、姣、妯、婷、姿、媚、婉、妩、倩、兰、达、耀、兴、荣、华、旺、盈、丰、余、昌、盛"
first_name_list = [item for item in first_name.split('、')]
last_name_list = [item for item in last_name.split('、')]
ptitle_list = ['讲师', '副教授', '教授']

template = "into teacher(TNO,DNO,TNAME,Tsex,CONTACTNUM,PTITLE,TPASSWORD) " \
           "values('%s','%s','%s','%s','%s','%s','7654321ab')\n"


def get_ptitle():
    return ptitle_list[math.floor(random() * len(ptitle_list))]


def get_firstName():
    index = math.floor(random() * len(first_name_list))
    return first_name_list[index]


def get_lastName():
    tag = random() > 0.5
    index = math.floor(random() * len(last_name_list))
    if tag:
        return last_name_list[index]
    else:
        lastName = last_name_list[index]
        index = math.floor(random() * len(last_name_list))
        return lastName + last_name_list[index]
    pass


def get_tname():
    return get_firstName().strip() + get_lastName().strip()


def get_sex():
    if random() > 0.5:
        return '女'
    else:
        return '男'


def get_mobile():
    st = ['15', '17', '18', '13']
    mobile = st[math.floor(random() * len(st))]
    for i in range(9):
        mobile += str(math.floor(random() * 10))
    return mobile


if __name__ == '__main__':
    f = open('TEACHER.sql', 'w', encoding='utf-8')
    f.write("insert all\n".upper())
    for i in range(1, 16):
        cnt = 0
        for j in range(30):
            cnt += 1
            TNO = 'ND%02dTNO%03d' % (i, cnt)
            DNO = 'ND%02d' % i
            Tname = get_tname()
            Tsex = get_sex()
            contactnum = get_mobile()
            ptitle = get_ptitle()
            sql = template % (TNO, DNO, Tname, Tsex, contactnum, ptitle)
            f.write(sql.upper())
    f.write('select 1 from dual;\n')
    f.close()
